<template>
  <div>
    <uni-row>
      <uni-col :span="12">
        <uni-title align="center" type="h2" title="姓名:"></uni-title>
      </uni-col>
      <uni-col :span="12">
        <uni-title align="center" type="h2" :title="userInfo.nickname"></uni-title>
      </uni-col>
    </uni-row>
    <uni-row>
      <uni-col :span="12">
        <uni-title align="center" type="h2" title="账号:"></uni-title>
      </uni-col>
      <uni-col :span="12">
        <uni-title align="center" type="h2" :title="userInfo.username"></uni-title>
      </uni-col>
    </uni-row>
    <uni-row>
      <uni-col :span="12">
        <uni-title align="center" type="h2" title="人员编号:"></uni-title>
      </uni-col>
      <uni-col :span="12">
        <uni-title align="center" type="h2" :title="userInfo.username"></uni-title>
      </uni-col>
    </uni-row>
    <uni-row>
      <uni-col :span="12">
        <uni-title align="center" type="h2" title="所在车间:"></uni-title>
      </uni-col>
      <uni-col :span="12">
        <uni-title align="center" type="h2" :title="userInfo.deptName"></uni-title>
      </uni-col>
    </uni-row>
    <uni-row>
      <uni-col :span="12">
        <uni-title align="center" type="h2" title="人员岗位:"></uni-title>
      </uni-col>
      <uni-col :span="12">
        <uni-title align="center" type="h2" :title="roleName"></uni-title>
      </uni-col>
    </uni-row>
    <!-- <button class="button2" @click="setUpIp">设置IP</button> -->
    <button class="button" @click="signOut">退出登录</button>
  </div>
  <uni-popup ref="inputDialog" type="dialog">
    <uni-popup-dialog  mode="input" title="输入内容" :value="ip"
                      placeholder="请输入服务器ip地址" @confirm="handleConfrim"></uni-popup-dialog>
  </uni-popup>
</template>

<script setup lang="ts">

import UniForms from "../../uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
import UniFormsItem from "../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
import {useStore} from "vuex";
import {UserInfo} from "../../sql/domin";
import {computed, ref} from "vue";
import UniRow from "../../uni_modules/uni-row/components/uni-row/uni-row.vue";
import UniCol from "../../uni_modules/uni-row/components/uni-col/uni-col.vue";
import UniTitle from "../../uni_modules/uni-title/components/uni-title/uni-title.vue";
import {BASE_IP} from "../../util/Constants";
import {base_ip} from "../../util/request";
import {onLoad} from "@dcloudio/uni-app";

const store = useStore()

const userInfo: UserInfo = store.getters.userinfo

const inputDialog = ref()

const ip = ref('')

onLoad(()=>{
  ip.value = base_ip.value
})

const roleName = computed(() => {
  switch (userInfo.role) {
    case "head":
      return "主任"
    case "bzz":
      return '班组长'
    case "czy":
      return '操作员'
  }
})

const signOut = () =>{
  store.dispatch('LOGIN_OUT')
}

const setUpIp = () => {
  inputDialog.value.open()
}

const handleConfirm = (val:string) => {
  uni.setStorage({
    key:BASE_IP,
    data:val,
    success:()=>{
      base_ip.value = val
    }
  })
}

</script>

<style>

* {
  text-align: center;
}

.button2 {
  background-color: #15d000;
  position: absolute;
  bottom: 50px;
  color: white;
  width: 100%;
  font-size: large;
}

.button {
  background-color: #d00000;
  position: absolute;
  bottom: 5px;
  color: white;
  width: 100%;
  font-size: large;
}

</style>
